<?php

/**
 * Zamienia tekst na znaki z (podstawowego) ASCII
 *
 * @category   Core
 * @package    Core_Filter
 * @copyright  Copyright (c) 2008 Kuśmierz Adam
 * @author Adam Kuśmierz
 */

class Core_Filter_ASCIIchars implements Zend_Filter_Interface
{
	/**
	 * Perform remove non-ascii chars filter
	 *
	 * @param string $text
	 * @return string
	 */
	public function filter($txt)
	{
		$utf2pl = array("\xc4\x85" => "a", "\xc4\x84" => "A",
						"\xc4\x87" => "c", "\xc4\x86" => "C",
						"\xc4\x99" => "e", "\xc4\x98" => "E",
						"\xc5\x82" => "l", "\xc5\x81" => "L",
						"\xc3\xb3" => "o", "\xc3\x93" => "O",
						"\xc5\x9b" => "s", "\xc5\x9a" => "S",
						"\xc5\xba" => "z", "\xc5\xb9" => "Z",
						"\xc5\xbc" => "z", "\xc5\xbb" => "Z",
						"\xc5\x84" => "n", "\xc5\x83" => "N"
		);
		$txt = strtr($txt, $utf2pl);
		preg_replace('/[^a-z0-9]/i', '-', $txt);
		preg_replace('/-{2,}/i', '-', $txt);
		$txt = iconv('utf-8', 'ASCII//TRANSLIT', $txt);
		if (!empty($txt))
			return $txt;
		return 'no-name';
	}
}
